function asyncGeneratorStep(t, e, i, a, n, r, s) {
    try {
        var o = t[r](s), u = o.value;
    } catch (t) {
        return void i(t);
    }
    o.done ? e(u) : Promise.resolve(u).then(a, n);
}

function _asyncToGenerator(o) {
    return function() {
        var t = this, s = arguments;
        return new Promise(function(e, i) {
            var a = o.apply(t, s);
            function n(t) {
                asyncGeneratorStep(a, e, i, n, r, "next", t);
            }
            function r(t) {
                asyncGeneratorStep(a, e, i, n, r, "throw", t);
            }
            n(void 0);
        });
    };
}

var _global = global, regeneratorRuntime = _global.regeneratorRuntime;

Component({
    options: {
        multipleSlots: !0
    },
    externalClasses: [ "custom-bar", "custom-box", "custom-tab_head" ],
    properties: {
        customStyle: String,
        tabs: {
            type: Array,
            value: [],
            observer: function(t, e) {
                t.length !== e.length && this.setSliderWidth();
            }
        },
        index: {
            type: Number,
            value: 0,
            observer: function(t) {
                var e = +t;
                !Number.isInteger(e) || e < 0 || (+this.data.activeIndex === e ? this.setData({
                    activeIndex: e
                }) : this.emit(e));
            }
        },
        fixed: {
            type: Boolean,
            value: !1
        },
        padding: {
            type: Number,
            value: 50
        },
        top: String,
        background: {
            type: String,
            value: "#fff"
        },
        badges: {
            type: Array,
            value: []
        },
        maskHeight: {
            type: String,
            value: "50px"
        }
    },
    data: {
        sliderWidth: "",
        sliderOffset: "",
        activeIndex: 0
    },
    ready: function() {
        this.init(this.data.activeIndex);
    },
    methods: {
        init: function(t) {
            var e = this.data.activeIndex;
            this.setSliderWidth(), this.emit(Math.max(t, e));
        },
        getTimeStamp: function() {
            return this.timeStamp || (this.timeStamp = Array.from(Array(this.data.tabs.length), function() {
                return {};
            })), this.timeStamp;
        },
        setSliderWidth: function() {
            var t = _asyncToGenerator(regeneratorRuntime.mark(function t() {
                var e, i, a, n;
                return regeneratorRuntime.wrap(function(t) {
                    for (;;) switch (t.prev = t.next) {
                      case 0:
                        return t.next = 2, this.getSilderWidth();

                      case 2:
                        e = t.sent, i = this.data, a = i.activeIndex, n = i.padding, this.setData({
                            sliderWidth: e,
                            sliderOffset: n / 2 + e * a
                        });

                      case 5:
                      case "end":
                        return t.stop();
                    }
                }, t, this);
            }));
            return function() {
                return t.apply(this, arguments);
            };
        }(),
        getSilderWidth: function() {
            var r = this;
            return new Promise(function(n) {
                wx.createSelectorQuery().in(r).select(".weui-navbar").boundingClientRect(function(t) {
                    var e = r.data, i = e.padding, a = e.tabs;
                    n(t ? (t.width - i) / a.length : 0);
                }).exec();
            });
        },
        touchStart: function(t) {
            var e = t.currentTarget.dataset.index, i = t.timeStamp;
            this.getTimeStamp()[e].touchStartTime = i;
        },
        touchEnd: function(t) {
            var e = t.currentTarget.dataset.index, i = t.timeStamp;
            this.getTimeStamp()[e].touchEndTime = i;
        },
        onChange: function(t) {
            var e = this, i = t.currentTarget.dataset.index, a = t.timeStamp, n = this.getTimeStamp()[i];
            if (n.touchEndTime - n.touchStartTime < 350) {
                var r = a, s = n.lastTapTime;
                (n.lastTapTime = r) - s < 300 ? i === this.data.activeIndex && (clearTimeout(this.lastTapTimeoutFunc), 
                this.triggerEvent("doubletap", {
                    index: i
                }, {})) : this.lastTapTimeoutFunc = setTimeout(function() {
                    i !== e.data.activeIndex && e.emit(+i);
                }, 300);
            }
        },
        emit: function(t) {
            var e = this;
            if (!this.change) {
                this.change = !0;
                var i = this.data, a = i.sliderWidth, n = i.padding, r = !1;
                this.recordTab = this.recordTab || [], this.recordTab.includes(t) || (this.recordTab.push(t), 
                r = !0), this.setData({
                    activeIndex: t,
                    sliderOffset: n / 2 + a * t
                }, function() {
                    wx.setTimeout(function() {
                        return e.change = !1;
                    }, 500), e.triggerEvent("change", {
                        index: t,
                        reset: r
                    }, {});
                });
            }
        },
        resetTab: function() {
            this.recordTab = [];
        }
    }
});